﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Doo.Scripts;
using System.ComponentModel;

namespace Doo.WebUI
{
    public class DooUserControl : UserControl, IUseScriptObject
    {
        public string ScriptObjectID
        {
            get;
            set;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //设置ScriptObject的父子级关系
            var p = NamingContainer;
            if (!(p is IUseScriptObject)) return;

            var so = ScriptObject;
            if (so == null) return;

            var pso = (p as IUseScriptObject).ScriptObject;
            if (pso == null) return;

            so.ParentObject = pso;
        }

        private Controls.ScriptObject _sobject;
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Controls.ScriptObject ScriptObject
        {
            get { return _sobject ?? (string.IsNullOrEmpty(ScriptObjectID) ? null : FindControl(ScriptObjectID) as Controls.ScriptObject); }
            set { _sobject = value; }
        }
    }
}
